public class LC_977 {
    public int[] sortedSquares(int[] nums) {
        int[] arr = new int[nums.length];
        int left = 0 , right = nums.length-1;
        int i = nums.length-1;
        while(i >= 0){
            if(nums[right] * nums[right] > nums[left] * nums[left]){
                arr[i] = nums[right] * nums[right];
                right--;
            }else{
                arr[i] = nums[left] * nums[left];
                left++;
            }
            i--;
        }
        return arr;
    }
}
